#include "netfwd.h"
#include "list.h"
#include "pagemempool.h"

#define PERSON_COUNT 9

struct Person
{
	int64_t 	m_uin;
	char 		m_name[128];
};

Person s_person_arry[PERSON_COUNT];

typedef List<Person> PersonList_T;
typedef PageMemPool<Person> PersonAlloc_T;

PersonList_T  s_person_list;
PersonAlloc_T s_person_alloc;

int32_t main( int32_t argc, char * argv[] )
{
	Person * person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
	sprintf( person->m_name, "%s.%d", "calmwu", 99990 );
	person->m_uin = 99990;	
	s_person_list.insert( s_person_list.get_end_iterator(), person );
	
	person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
	sprintf( person->m_name, "%s.%d", "calmwu", 99991 );
	person->m_uin = 99991;	
	s_person_list.insert( s_person_list.get_iterator(), person );

	person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
	sprintf( person->m_name, "%s.%d", "calmwu", 99995 );
	person->m_uin = 99995;	
	s_person_list.insert( s_person_list.get_iterator(), person );		
	
	for( int32_t index = 0; index < PERSON_COUNT; ++index )
	{
		Person * person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
		sprintf( person->m_name, "%s.%d", "calmwu", index );
		person->m_uin = index;
		s_person_list.push_back( person );
	}
	
	person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
	sprintf( person->m_name, "%s.%d", "calmwu", 99992 );
	person->m_uin = 99992;	
	s_person_list.insert( s_person_list.get_end_iterator(), person );	
	
	PersonList_T::iterator iter = s_person_list.get_iterator();
	while( !iter.is_done() )
	{
		fprintf( stderr, "name=[%s], uin=[%ld]\n",
			iter.value()->m_name, iter.value()->m_uin );
		
		if( iter.value()->m_uin == 8 )
		{
			person = (Person*)s_person_alloc.alloc( __FILE__, __LINE__ );
			sprintf( person->m_name, "%s.%d", "calmwu", 99998 );
			person->m_uin = 99998;				
			s_person_list.insert( iter, person );
		}
        iter.next();
	}	
	fprintf( stderr, "player count %d\n", s_person_list.size() );
	
	iter = s_person_list.get_iterator();
	while( !iter.is_done() )
	{
		fprintf( stderr, "name=[%s], uin=[%ld]\n",
			iter.value()->m_name, iter.value()->m_uin );	
        iter.next();
	}
	
	Person * del_person = NULL;
	
	while( del_person = s_person_list.pop_head() )
	{
		fprintf( stderr, "del name=[%s], uin=[%ld]\n",
			del_person->m_name, del_person->m_uin );
		s_person_alloc.release( del_person, __FILE__, __LINE__ );
	}
	
	/*
	iter = s_person_list.get_iterator();
	while( !iter.is_done() )
	{
		del_person = s_person_list.erase( iter );
		s_person_alloc.release( del_person, __FILE__, __LINE__ );
	}
	*/
	fprintf( stderr, "player count %d\n", s_person_list.size() );
	return 0;
}

